#include <iostream>
#include <vector>
#include <string>

using namespace std;

size_t hashCount(const string& str, size_t legth, const vector<size_t>& p) {
    size_t hash = 0;
    for(size_t i = 0; i < legth; ++i) {
        hash += str[i]*p[legth - i - 1];
    }
    return hash;
}

void hashRecount(size_t& hash, const string& str, const string& subStr, size_t from, const vector<size_t>& p) {
    size_t subStrLen = subStr.length();
    hash -= str[from-subStrLen]*p[subStrLen - 1];
    hash += hash << 5;
    hash += str[from];
}

int main() {
    if(freopen("in.txt", "r", stdin)==NULL) {
        cout<<"Error: input file can't be opened";
        return 1;
    }

    string str;
    cin >> str;
    vector<size_t> pows(str.size(), 1);
    for(size_t i = 1; i < str.size(); ++i) {
        pows[i] = pows[i - 1] * 33;
    }
    while(cin.good()) {
        string subStr;

        cin >> subStr;
        size_t subStrLen, strHash, subStrHash;
    
        subStrLen = subStr.length();
        subStrHash = hashCount(subStr, subStrLen, pows);
        size_t i = subStrLen;
        bool calculated = false;
        bool finded = false;
        for(size_t i = subStrLen; i < str.length() + 1; ++i) {
            if(calculated) {
                hashRecount(strHash, str, subStr, i - 1, pows);
            } else {
                strHash = hashCount(str.substr(0, subStr.length()), subStrLen, pows);
                calculated = true;
            }
            if(strHash == subStrHash && !subStr.compare(str.substr(i - subStrLen, subStrLen))) {
                cout << i - subStrLen << endl;
                finded = true;
                break;
            }
        }
        if(!finded) {
            cout << "-1" << endl;
        }
    }

    return 0;
}
